package com.example.userdemo.quartz;

import com.example.userdemo.Job.TestJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class TestScheduler {
    public static void main(String[] args) throws SchedulerException {
        //获取任务调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        //定义任务调度实例，并与job绑定
        JobDetail job = JobBuilder.newJob(TestJob.class)
                .usingJobData("testJobDetail", "jobDetail数据存放")
                .withIdentity("testJob", "testJobGroup")
                .build();

        //定义触发器
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .usingJobData("testTrigger", "trigger数据存放")
                .withIdentity("testTrigger", "testTriggerGroup")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
                .build();

        //使用触发器调度任务的执行
        scheduler.scheduleJob(job, trigger);

        scheduler.start();
    }
}
